package com.grape.demo_graphql.resolver.mutation;

import graphql.kickstart.execution.context.DefaultGraphQLContext;
import graphql.kickstart.servlet.context.DefaultGraphQLServletContext;
import graphql.kickstart.tools.GraphQLMutationResolver;
import graphql.schema.DataFetchingEnvironment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author robin
 * @Date 2021/11/4
 * @Description
 */
@Slf4j
@Component
public class UploadFileMutation implements GraphQLMutationResolver {
    public UUID uploadFile(DataFetchingEnvironment env) {
        DefaultGraphQLServletContext context = env.getContext();
        context.getFileParts().forEach(
                part -> {
                    log.info("uploading {}, size: {}", part.getSubmittedFileName(), part.getSize());
                }
        );
        return UUID.randomUUID();

    }
}
